package com.zdemo.pressure;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

public class RequestRunner {
	private static final ExecutorService exec = new RequestThreadPoolExecutor(10, 10, 1000,
			TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new RequestThreadFactory("RequestThreadPoolExecutor"), new RejectedExecutionHandler() {

				@Override
				public void rejectedExecution(Runnable r,
						ThreadPoolExecutor executor) {
					System.out.println("-----------------");
				}
		
	});
	
	public static void main(String[] args) {
		
		Logger log3 = Logger.getLogger("lavasoft.blog");
		log3.info("info3");
		
		for(int i = 0; i < 100; i++) {
			Runnable r = new Thread() {
				@Override
				public void run() {
					
					URL url;
					URLConnection urlconn;
					int status = 0;
					try {
						url = new URL("http://222.35.5.21:20081/search/exchangeTop?pageSize=5&pageIndex=1");
						urlconn = url.openConnection();
						HttpURLConnection httpConnection = (HttpURLConnection) urlconn;
						status = httpConnection.getResponseCode();
					} catch(IOException e) {
						e.printStackTrace();
					}
				}
			};
			exec.execute(new RequestThread(r));
		}
	}
}
